package com.xncoding.valid.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class FlagValuesConstraintValidator implements ConstraintValidator<EnumValues,Integer> {

    private Set<Integer> set = new HashSet<>();

    @Override
    public void initialize(EnumValues flagValues) {
        for (int i:flagValues.values()) {
            set.add(i);
        }
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
